`
https://leetcode.cn/problems/maximum-subarray/
`

/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSubArray = function (nums) {
  let left = 0, right = 0
  let curSum = 0, maxSum = -Infinity

  while (right < nums.length) {
    curSum += nums[right]
    right++

    maxSum = Math.max(maxSum, curSum)

    // 窗口和为负数时收缩
    while (curSum < 0) {
      curSum -= nums[left]
      left++
    }
  }

  return maxSum
};